<template>
	<view class="scrool-page">
		<block v-for="(item, i) in integrals" :key="i">
			<view class="consumption-item">
				<view class="item-left">{{item.consumptionDescText}}</view>
				<view :class="'item-right num'+item.consumptionType">{{item.consumptionType==1?"+":"-"}} {{item.consumptionNum}}</view>
			</view>
		</block>
		<u-divider v-show="pageNum >= totalPages">没有更多了</u-divider>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				integrals: [
				],
				pageNum: 1,
				pageSize: 25,
				totalPages: 0, //总页数
				total: '', //总条数
			};
		},
		onLoad() {
			this.pageNum = 1;
			this.getUserIntegralConsumptions();
		},
		methods: {
			/**
			 * 下拉刷新回调函数
			 */
			onPullDownRefresh() {
				console.log("下拉刷新")
				this.pageNum = 1;
				this.getUserIntegralConsumptions();
				setTimeout(function() {
					uni.stopPullDownRefresh();
				}, 500);
			},
			/**
			 * 上拉加载更多
			 */
			onReachBottom() {
				console.log("上拉加载更多" + this.pageNum + "  " + this.totalPages)
				if (this.pageNum >= this.totalPages) {
					return
				}
				// 加载更多数据
				this.pageNum++;
				this.getUserIntegralConsumptions();
			},
			getUserIntegralConsumptions() {
				this.$u.api.getUserIntegralConsumptions({
						pageNum: this.pageNum,
						pageSize: this.pageSize,
						userId: this.$store.state.userinfo.id,
						type: 1, //1:行业标准
					})
					.then(res => {
						this.total = res.total;
						this.totalPages = res.totalPages;
						var resultList = res.rows;
						if (this.pageNum == 1) {
							this.integrals = resultList;
						} else {
							this.integrals = this.integrals.concat(resultList);
						}
					});
			}
		}
	}
</script>
<style lang="scss">
	.scrool-page {
		display: flex;
		flex-direction: column;
		width: 100%;
		height: 100%;
	}
	.consumption-item {
		display: flex;
		justify-content: flex-end;
		text-align: center;
		align-items: center;
		height: 60rpx;
		border-bottom: solid 1rpx #E5E5E5;
		margin-right: 20rpx;
		margin-left: 20rpx;
		.item-left {
			font-size: 30rpx;
			font-family: PingFang SC;
		}
		.item-right {
			font-size: 30rpx;
			font-family: PingFang SC;
			margin-left: auto;
		}
	}
	.num1 {
		color: #3BA2FF;
	}
	.num2 {
		color: #1A1A1A;
	}
</style>
